package com.shanjupay.apiagent.controller;

import com.alibaba.fastjson.JSON;
import com.shanjupay.user.api.AccountService;
import com.shanjupay.user.api.dto.AccountDTO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/config")
@RefreshScope
public class TestConfigController {

    @Value("${management.endpoints.web.exposure.include}")
    private String useLocalCache;

    @Reference
    private AccountService accountService;

    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
    private Registration registration; // 服务注册

    @RequestMapping("/get")
    public String get() {
        AccountDTO account = new AccountDTO();
        account.setId(1L);
        account.setName("xufan");
        AccountDTO rst = accountService.createAccount(account);



        return registration.getPort()+ " : " + useLocalCache + "<br/>" +JSON.toJSONString(rst);
    }

}
